package next.fire.mq.management;

import com.talkyun.utils.http.HttpConnector;
import com.talkyun.utils.http.HttpResult;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

public class RabbitManagement {

    public static void main(String[] args) throws IOException {
        //curl -i -u guest:guest http://localhost:55672/api/vhosts

        String name = "admin";
        String password = "admin@mq123";

        String authString = name + ":" + password;
        System.out.println("Auth: " + authString);

        // Base64编码

        byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes(StandardCharsets.UTF_8));

        String authEncode = new String(authEncBytes);
        System.out.println(authEncode);

        // Authorization格式，注意“Basic ” 有个空格
        // conn.setRequestProperty("Authorization", "Basic " + authStringEnc);

        Map<String, String> header = new HashMap<>();
        header.put("Authorization", "Basic " + authEncode);
        HttpConnector http = new HttpConnector("http://120.25.135.172:5682/api/users/bdcc/permissions");
        HttpResult result = http.sendWithHeader("GET", header, null);
        System.out.println(result.getStatus() + " : " + result.getResult());



    }
}
